package cn.fenqing168.nio;

import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;

/**
 * @author fenqing
 */
public class MappedByteBufferTest {

    public static void main(String[] args) {
        //创建一个文件对象
        try (FileChannel channel = FileChannel.open(Paths.get("./nio/", "fileChannel1.txt"), StandardOpenOption.WRITE, StandardOpenOption.READ)) {
            //创建一个MappedByteBuffer
            MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE, 0, 10);
            //对Buffer直接put数据
            map.putChar(0, 'A');
            map.putChar(1, 'A');
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
